package com.szp.lg.blog.Controller;

import com.szp.lg.blog.pojo.Blog;
import com.szp.lg.blog.sercvice.BlogService;
import com.szp.lg.blog.util.PageQueryUtil;
import com.szp.lg.blog.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.persistence.Id;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
//@RequestMapping("/blog")
public class BlogController {
    @Autowired
    BlogService blogService;

    @RequestMapping("/findAll")
    @ResponseBody
    public PageResult findAll(){
        return blogService.findAll(null);
    }
    @RequestMapping(value = {"","/","/index","index.html"})
    public String index(@RequestParam(required = false) Map<String, Object> params, HttpServletRequest request){
        if(null == params.get("page")){
            params.put("page","1");
        }
        if(null == params.get("limit")){
            params.put("limit", "2");
        }
        PageQueryUtil pageUtil = new PageQueryUtil(params);
        request.setAttribute("pageResult", blogService.findAll(pageUtil));
        return "client/index";
    }
}
